﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace FinalTestMachine.View.Dispenser
{
    /// <summary>
    /// Wnd_MeasureXYViewModel.xaml 的交互逻辑
    /// </summary>
    public partial class Wnd_MeasureXYViewModel : Window
    {
        public Wnd_MeasureXYViewModel()
        {
            InitializeComponent();
        }

        void WriterToUser(string str, Brush brush, bool IsClear)
        {
            Lv_msg.WriteToUser(str, brush, IsClear);
        }


        private void Btn_MeasureStart_Click(object sender, RoutedEventArgs e)
        {
            btn_MeasureStart.IsEnabled = false;
            //Task.Run(() =>
            //{
            //    try
            //    {
            //        WriterToUser("开始标定...", Brushes.White, true);
            //        MeasureHeightHelper.Cur.Run();
            //        if (MeasureHeightHelper.Cur.IsMeasureOK)
            //        {
            //            MeasureXY_Hepler.Cur.Run();
            //            if (MeasureXY_Hepler.Cur.IsMeasureOK)
            //            {
            //                this.Dispatcher.BeginInvoke(new Action(() =>
            //                {

            //                    btn_MeasureStart.IsEnabled = true;


            //                }));
            //                WriterToUser("标定成功...", Brushes.Green, true);
            //                return;
            //            }
            //            else
            //            {
            //                throw new Exception("标定XY失败！");
            //            }
            //        }
            //        else
            //        {
            //            throw new Exception("测高失败！");
            //        }



            //    }
            //    catch (Exception ex)
            //    {
            //        this.Dispatcher.Invoke(() =>
            //        {
            //            MessageBox.Show(ex.Message, "标定失败");
            //            btn_MeasureStart.IsEnabled = true;

            //        });

            //    }


            //});
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //try
            //{
            //    //绑定
            //    dg_DxDyData.ItemsSource = MeasureXYAndHeightMsg.Cur.dxDyMsgsList;
            //    dg_DzData.ItemsSource = MeasureXYAndHeightMsg.Cur.dzMsgsList;
            //    void bingding(TextBox textBox, object ob)
            //    {
            //        Binding binding = new Binding();
            //        binding.Source = ob;
            //        binding.Path = new PropertyPath("GetValue");
            //        textBox.SetBinding(TextBox.TextProperty, binding);
            //    }
            //    bingding(tb_dx, MeasureXYAndHeightMsg.Cur.dxAverage);
            //    bingding(tb_dy, MeasureXYAndHeightMsg.Cur.dyAverage);
            //    bingding(tb_dz, MeasureXYAndHeightMsg.Cur.dzAverage);

            //    bingding(tb_dxdx, MeasureXYAndHeightMsg.Cur.dxdx);
            //    bingding(tb_dydy, MeasureXYAndHeightMsg.Cur.dydy);

            //    bingding(tb_dzdz, MeasureXYAndHeightMsg.Cur.dzdz);


            //    MeasureHeightHelper.Cur.WriteToUserEvent += WriterToUser;
            //    MeasureXY_Hepler.Cur.WriteToUserEvent += WriterToUser;
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}


        }

        private void Window_Closed(object sender, EventArgs e)
        {

            //MeasureHeightHelper.Cur.WriteToUserEvent -= WriterToUser;
            //MeasureXY_Hepler.Cur.WriteToUserEvent -= WriterToUser;

        }

        private void Btn_clear_Click(object sender, RoutedEventArgs e)
        {
            //MeasureXYAndHeightMsg.Cur.dxDyMsgsList.Clear();
            //MeasureXYAndHeightMsg.Cur.dzMsgsList.Clear();

        }
    }
}
